﻿#region Usings

using System.Windows;
using System.Windows.Interactivity;
using SilverBox.Physics;

#endregion

namespace SilverBox.Behaviors
{
    public class PhysicsContextBehavior : Behavior<FrameworkElement>
    {
        public static readonly DependencyProperty GravityProperty = DependencyProperty.Register("Gravity",
                                                                                                typeof (double),
                                                                                                typeof (
                                                                                                    PhysicsContextBehavior
                                                                                                    ),
                                                                                                new PropertyMetadata(
                                                                                                    10.0d));

        public double Gravity
        {
            get { return (double) GetValue(GravityProperty); }
            set { SetValue(GravityProperty, value); }
        }


        protected override void OnAttached()
        {
            base.OnAttached();

            var context = new PhysicsContext();
            context.Gravity = Gravity;

            PhysicsContext.SetPhysicsContext(AssociatedObject, context);
        }
    }
}